#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;
/*
bool cmp(int a, int b)
{
    return a<b;
}
bool cmp(float a, float b)
{
    return a<b;
}
bool cmp(long a, long b)
{
    return a<b;
}
*/
template <class T>
T min(T& a, T& b)
{
    if(a<b)
       return a;
    else
       return b;
}
class student
{
    public:
        int id;
        string name;
        student ()
        {
            id = 0;
            name = "";
        }
        student(int pid, string pname)
        {
            id = pid;
            name = pname;
        }
        void show()
        {
            cout<<id<<" "<<name<<endl;
        }
        friend bool operator< (const student& st1,const student& st2)
        {
            return st1.id < st2.id;
        }
        friend ostream& operator<<(ostream &out, const student st)
        {
            out<<"("<<st.id<<": "<<st.name<<")";
            return out;
        }
        friend bool operator == (const student st1,const student st2)
        {
            return st1.id == st2.id;
        }

};


int main()
{
    int b1 =1.0,b2 = 3.0;    
    cout<<min(b1,b2)<<endl;
    float a1=2,a2=3;
    cout<<min(a1,a2)<<endl;
    long c1 =1000, c2 = 59;
    cout<<min(c1,c2)<<endl;
    string s1 = "John", s2 = "Mary";
    cout <<min(s1,s2)<<endl;
    
    student st1(1,"mary"),st2(3,"john");
    student st3 = min(st1,st2);
    st3.show();
    
    
    
    int a[] = {1,3,6,2,2};
    sort(a,a+4);
    for(int i = 0; i<4; i++)
        cout<<a[i]<<endl;
    auto pmin = min_element(a,a+4);
    cout<<"min ="<<(*pmin)<<endl;
    cout<<"counter ="<<count(a,a+5,3)<<endl;


    vector<int> va = {23,14,59,24,39,29};
    sort(va.begin(),va.end());
    cout<<"after sort"<<string(20,'*')<<endl;
    //for(vector<int>::iterator it = va.begin(); it != va.end(); it++)
    //    cout << *it<<endl;
    auto it = va.begin();
    for(;it != va.end(); it++)
        cout<< *it<<endl;



    vector<student> students = {{10,"zhangsan"},{12,"lisi"},{9,"wangwu"}};
    students.push_back(st1);
    students.push_back(st2);
    sort(students.begin(),students.end());
    //for(vector<student>::iterator it = students.begin();it != students.end();it++)
    //    cout<<it->id<<" "<<it->name<<endl;
    for(auto item: students)
    {
        //item.show();
        cout<<item;
        //cout<<item.id<<" "<<item.name<<endl;
    }
    student tmp(9,"");
    auto p = find(students.begin(),students.end(),tmp);
    cout<<*p;
    vector<student> v1,v2(10);
    v1 = students;
    copy(v1.begin(),v1.end(),v2.begin());
    cout<<endl<<string(30,'*')<<endl;
    for(auto item : v2)
        cout<<item;

}